#include "Splines.h"

class Fun : public Function
{
public:
    double f(double x) {return 1/(1+25*x*x);}
    double df(double x) {return -50*x/(1+25*x*x)/(1+25*x*x);}
    double ddf(double x) {return (3750*x-50)/(1+25*x*x)/(1+25*x*x)/(1+25*x*x);}
};

int main(int argc, char * argv[])
{
    int N=atoi(argv[1]);
    double m;
    vector<double> x,y,z;
    Fun g;
    Splines s;
    //cin >> N;
    for(int i=0;i<N;i++)
    {
        m = -1+2.0*i/(N-1);
        x.push_back(m);
        y.push_back(g.f(m));
    }
    s = interpolation(x,y,g.df(-1),g.df(1),g.ddf(-1),g.ddf(1),"Bsplines","cubic","ccs");
    s.fileprintspline("dataA.txt");
    for(int i=0;i<N-1;i++)
    {
        double xm=(x[i]+x[i+1])/2;
        m=fabs(g.f(xm)-s.value(xm));
        z.push_back(m);
    }
    m = maxvalue(z);
    cout << "max error: " << m << endl;
}